package com.xiaoyan.texteditor.UI;

import javax.swing.*;
import java.awt.*;

/**
 * ClassName: AboutDialog
 * Package: com.xiaoyan.texteditor.UI
 * Description:
 *
 * @Author Xiaoyan_Lu
 * @Create 2023/12/7 18:44
 * @Version 1.0
 */
public class AboutDialog extends JDialog {
    private static final int WIDTH = 425;
    private static final int HEIGHT = 300;

    public AboutDialog(Frame owner) {
        super(owner,"关于记事本");
        this.setLayout(new BorderLayout());
        //设置窗口大小
        this.setSize(WIDTH,HEIGHT);
        //设置窗口位置
        this.setAboutDialogLocation(owner);
        //添加组件
        this.addComponent();
    }

    private void addComponent() {
        JLabel jLabel = new JLabel("<html>有问题可联系作者:<br/>xiaoyan_lu2021@163.com</html>");
        jLabel.setPreferredSize(new Dimension(400,180));
        jLabel.setFont(new Font("微软雅黑",Font.BOLD,24));
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
        this.getContentPane().add(jLabel,BorderLayout.CENTER);
    }

    private void setAboutDialogLocation(Frame owner) {
        int x = owner.getX() + owner.getWidth()/2 - this.getWidth()/2;
        int y = owner.getY()+ owner.getHeight()/2 - this.getHeight()/2;
        this.setLocation(x,y);
    }
}
